home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 43 / Amiga Format CD43 (1999)(Future Publishing)(GB)(Track 1 of 2)[!][issue 1999-09].iso / -serious- / programming / other / gtdrag / include / libraries / gtdrag.h next >
C/C++ Source or Header  |  1999-06-14  |  10KB  |  293 lines

  1. #ifndef LIBRARIES_GTDRAG_H
  2. #define LIBRARIES_GTDRAG_H 1
  3. /*
  4. **  $VER: gtdrag.h 3.8 (10.6.99)
  5. **  Includes Release 3.2
  6. **
  7. **  Drag&Drop with GadTools
  8. **
  9. **  Copyright ©1999 pinc Software.
  10. **  All rights Reserved.
  11. */
  12.  
  13. #ifndef EXEC_LISTS_H
  14. #include <exec/lists.h>
  15. #endif
  16.  
  17. #ifndef UTILITY_HOOKS_H
  18. #include <utility/hooks.h>
  19. #endif
  20.  
  21.  
  22. #ifndef reg
  23. #define reg(x) register __ ## x
  24. #endif
  25.  
  26.  
  27. /********************* ObjectDescription structure *********************/
  28.  
  29. /* the ObjectDescription structure describes the contents of the object
  30.  * being dragged.
  31.  */
  32.  
  33. struct ObjectDescription
  34. {
  35.   APTR   od_Object;           /* the pointer to the object */
  36.   ULONG  od_GroupID;          /* DataTypes-GroupID (see datatypes.h) */
  37.   ULONG  od_Type;             /* rough format of the object */
  38.   ULONG  od_InternalType;     /* application related type */
  39.   STRPTR od_Owner;            /* owner name or NULL if you are the owner */
  40.   APTR   od_UserData;
  41. };
  42.  
  43. /** Values for od_Type **/
  44.  
  45. #define ODT_UNKNOWN 0    /* should only be used rarely    */
  46. #define ODT_STRING 1     /* simple c-string (STRPTR)      */
  47. #define ODT_NODE 2       /* (struct Node *)               */
  48. #define ODT_IMAGENODE 4  /* (struct ImageNode *)          */
  49. #define ODT_TREENODE 8   /* (struct TreeNode *)           */
  50. #define ODT_IMAGE 16     /* (struct Image *)              */
  51. #define ODT_ICON 32      /* (struct DiskObject *)         */
  52. #define ODT_IFF 64       /* pointer to an IFF-data stream */
  53. #define ODT_LOCK 128     /* a file lock                   */
  54. #define ODT_DATATYPE 256 /* a datatype object             */
  55. #define ODT_BITMAP 512   /* (struct BitMap *)             */
  56.  
  57.  
  58. /********************* DropMessage structure *********************/
  59.  
  60. /* You receive the DropMessage structure if someone has dropped an object
  61.  * on a gadget or in a window of your application. The IAddress field of
  62.  * the IntuiMessage points to this structure.
  63.  * Remember: all fields are read-only!
  64.  */
  65.  
  66. struct DropMessage
  67. {
  68.   struct MinNode dm_Node;
  69.   struct ObjectDescription dm_Object;  /* dragged object */
  70.   struct Gadget *dm_Gadget;     /* source gadget */
  71.   struct Window *dm_Window;     /* source gadget's window */
  72.   struct Gadget *dm_Target;     /* pointer to the target gadget */
  73.   LONG   dm_SourceEntry;        /* the list position of the entry */
  74.   LONG   dm_TargetEntry;        /* dto. - may be higher than the number of entries */
  75.   ULONG  dm_Flags;
  76. };
  77.  
  78. #define DMF_DROPOVER 1          /* for treeviews */
  79.  
  80.  
  81. /** The flags for the IDCMP-MsgPort of your Window **/
  82.  
  83. #define DRAGIDCMP (LISTVIEWIDCMP | IDCMP_MOUSEBUTTONS)
  84. #define IDCMP_OBJECTDROP (IDCMP_DISKINSERTED | IDCMP_DISKREMOVED)
  85.  
  86. /* If you get a message of the IDCMP_OBJECTDROP class, someone dropped
  87.  * an object on a gadget or in a window that supports it.
  88.  * The IAddress-field of the IntuiMessage points to the DragMsg in this
  89.  * case.
  90.  */
  91.  
  92.  
  93. /** Tags to pass to GTD_AddGadget() (a few also for GTD_AddWindow()) **/
  94.  
  95. #define GTDA_TagBase    (TAG_USER + 0x90000)
  96.  
  97. /* describe the object */
  98.  
  99. #define GTDA_Object            GTDA_TagBase + 1   /* drag node from a non-listview */
  100. #define GTDA_GroupID           GTDA_TagBase + 2   /* Datatypes GroupID (see datatypes/datatypes.h) */
  101. #define GTDA_Type              GTDA_TagBase + 3   /* rough format of object */
  102. #define GTDA_InternalType      GTDA_TagBase + 4   /* internal type flag */
  103. #define GTDA_Mask              GTDA_InternalType  /* for compatibility */
  104. #define GTDA_Image             GTDA_TagBase + 5   /* image for dragging */
  105. #define GTDA_RenderHook        GTDA_TagBase + 6   /* render hook for listview/object */
  106. #define GTDA_ObjectDescription GTDA_TagBase + 7   /* pointer to struct ObjectDescription (contents will be copied) */
  107.  
  108. /* general use */
  109.  
  110. #define GTDA_Width         GTDA_TagBase + 8     /* width of icon (only for GTDA_RenderHook & GTDA_Images) */
  111. #define GTDA_Height        GTDA_TagBase + 9     /* height of a icon ("") */
  112. #define GTDA_NoDrag        GTDA_TagBase + 10    /* do not drag from this gadget */
  113. #define GTDA_AcceptTypes   GTDA_TagBase + 11    /* accept mask value for internal drag&drop */
  114. #define GTDA_AcceptMask    GTDA_AcceptTypes     /* for compatibility */
  115. #define GTDA_AcceptFunc    GTDA_TagBase + 12    /* function which checks for acceptance of the drag */
  116. #define GTDA_ObjectFunc    GTDA_TagBase + 13    /* callback function before a drag starts */
  117. #define GTDA_SourceEntry   GTDA_TagBase + 21    /* specifies the dm_SourceEntry field */
  118.  
  119. /* listview specials */
  120.  
  121. #define GTDA_ItemHeight    GTDA_TagBase + 14    /* height of a listview entry */
  122. #define GTDA_NoPosition    GTDA_TagBase + 15    /* no position highlighting and scrolling */
  123. #define GTDA_Same          GTDA_TagBase + 16    /* can move items inside its own list */
  124. #define GTDA_Images        GTDA_TagBase + 17    /* drags only images (listview MUST contain ImageNodes/TreeNodes) */
  125. #define GTDA_NoScrolling   GTDA_TagBase + 18    /* disables scrolling */
  126. #define GTDA_DropOverItems GTDA_TagBase + 19    /* objects are dropped over other items */
  127. #define GTDA_TreeView      GTDA_TagBase + 20    /* activate treeview specials */
  128. #define GTDA_DropBetweenItems GTDA_TagBase + 22  /* works only in conjungtion with GTDA_DropOverItems */
  129.  
  130.  
  131. /** Tags to pass to GTD_AddApp() **/
  132.  
  133. #define GTDA_InternalOnly  GTDA_TagBase + 42   /* only internal drag&drop */
  134. #define GTDA_NewStyle      GTDA_TagBase + 43   /* v3 is supported */
  135.  
  136.  
  137. /** Constants for passing to GTD_GetHook() **/
  138.  
  139. #define GTDH_IMAGE 1
  140. #define GTDH_TREE 2
  141. #define GTDH_IFFSTREAM 3
  142.  
  143. /** data for GTDH_IFFSTREAM, set Hook's h_data to this structure **/
  144.  
  145. struct IFFStreamHookData
  146. {
  147.   APTR  is_Pool;        /* a memory pool, buffer will be AllocMem()ed if NULL */
  148.   UBYTE *is_Buffer;     /* pointer to the buffer */
  149.   ULONG is_Size;        /* size of the buffer */
  150.   ULONG is_Position;    /* current stream position */
  151. };
  152.  
  153.  
  154. /********************* BOOPSI gadgets *********************/
  155.  
  156. #define BOOPSI_KIND 1000            /* GTD_AddGadget() - Type */
  157.  
  158. #define GMR_HANDLEYOURSELF (~0L)    /* GTD_HandleInput() return value */
  159.  
  160. #define GM_OBJECTDRAG   (GTDA_TagBase + 1000)    /* see structures below */
  161. #define GM_OBJECTDROP   (GTDA_TagBase + 1001)
  162. #define GM_RENDERDRAG   (GTDA_TagBase + 1002)
  163.  
  164. struct gpObjectDrag
  165. {
  166.   ULONG  MethodID;
  167.   struct ObjectDescription *gpod_Object;
  168.   struct Gadget *gpod_Source;      /* pointer to the source gadget */
  169.   struct
  170.   {
  171.     WORD X,Y;                      /* mouse coordinates */
  172.   }      gpod_Mouse;
  173. };
  174.  
  175. /* if GM_OBJECTDRAG is invoked you should return one of these values
  176.  * to report gtdrag that you could make use of it (to speed up things)
  177.  */
  178.  
  179. #define GMR_REJECTOBJECT 1
  180. #define GMR_ACCEPTOBJECT 2
  181. #define GMR_UPDATE 4               /* please update me (GM_RENDERDRAG will be invoked) */
  182. #define GMR_FINAL 8                /* store the result and do not ask again */
  183.  
  184.  
  185. struct gpObjectDrop
  186. {
  187.   ULONG  MethodID;
  188.   struct DropMessage *gpod_Message;
  189.   ULONG  gpod_Qualifier;
  190. };
  191.  
  192.  
  193. struct gpRenderDrag
  194. {
  195.   ULONG  MethodID;
  196.   struct GadgetInfo *gprd_GInfo;   /* gadget context */
  197.   struct RastPort *gprd_RPort;     /* already for use */
  198.   ULONG  gprd_Mode;                /* one of the GRENDER_xxx */
  199.   struct
  200.   {
  201.     WORD X,Y;                      /* mouse coordinates */
  202.   }      gprd_Mouse;
  203. };
  204.  
  205. #define GRENDER_HIGHLIGHT 0        /* highlight yourself */
  206. #define GRENDER_DELETE 1           /* delete all highlights */
  207. #define GRENDER_INTERIM 2          /* refreshing between two GRENDER_HIGHLIGHT */
  208.  
  209. /* You have to return TRUE if you processed the rendering yourself,
  210.  * otherwise gtdrag renders the standard highlighting.
  211.  * Returning FALSE will also let gtdrag stop sending you GM_OBJECTDRAG
  212.  * messages for the current drag.
  213.  */
  214.  
  215.  
  216.  
  217.                      /*************************/
  218. /********************* additional structures **********************\
  219. **                  **************************                    **
  220. **                                                                **
  221. ** The additional structures provide special rendering options in **
  222. ** listviews which are supported by gtdrag. The CallBack-Hooks    **
  223. ** necessary to display these are reachable via the API.          **
  224. ** See GTD_GetHook().                                             **
  225. **                                                                **
  226. \******************************************************************/
  227.  
  228.  
  229. /********************* ImageNode *********************/
  230.  
  231. /* The ImageNode structure is used to have both text and images in a listview.
  232.  * A render hook for this type is provided. It is not a must!
  233.  */
  234.  
  235. struct ImageNode
  236. {
  237.   struct ImageNode *in_Succ;
  238.   struct ImageNode *in_Pred;
  239.   UBYTE  in_Type;
  240.   BYTE   in_Pri;
  241.   STRPTR in_Name;
  242.   struct Image *in_Image;
  243. };
  244.  
  245.  
  246. /********************* Tree Structures *********************/
  247.  
  248. /* The TreeNode structure provides the possibility of displaying trees
  249.  * and images within a listview. A special tree hook is included.
  250.  */
  251.  
  252. struct TreeList
  253. {
  254.   struct MinList tl_View;
  255.   struct MinList tl_Tree;
  256. };
  257.  
  258. struct TreeNode
  259. {
  260.   struct ImageNode tn_Node;
  261.   struct MinNode tn_ViewNode;
  262.   struct MinList tn_Nodes;
  263.   ULONG  tn_DepthLines;
  264.   UBYTE  tn_Depth;
  265.   UWORD  tn_Flags;
  266.   WORD   tn_X,tn_Y;
  267.   APTR   tn_Special;
  268. };
  269.  
  270. #define TNF_NONE 0
  271. #define TNF_CONTAINER 1
  272. #define TNF_OPEN 2
  273. #define TNF_ADD 4
  274. #define TNF_REPLACE 8
  275. #define TNF_LAST 16          /* last node in group */
  276. #define TNF_STATIC 32        /* can't move node */
  277. #define TNF_NOSUBDIRS 64     /* can't create sub-directory (this flag is for you only) */
  278. #define TNF_SORT 256         /* sort by name (AddTreeNode() only) */
  279. #define TNF_HIGHLIGHTED 512  /* highlight name */
  280.  
  281.  
  282. /* from the ViewNode to the TreeNode */
  283. #define TREENODE(ln) ((struct TreeNode *)((UBYTE *)ln - sizeof(struct ImageNode)))
  284.  
  285. /* size of the knobs */
  286. #define TREEKNOBSIZE 6
  287.  
  288. /* is the mouse pointer over the tree-knob? */
  289. #define MouseOverTreeKnob(tn,h,msg) ((tn)->tn_X != -1 && (msg)->MouseX >= (tn)->tn_X && (msg)->MouseY >= (tn)->tn_Y+h && (msg)->MouseX <= (tn)->tn_X+TREEKNOBSIZE && (msg)->MouseY <= (tn)->tn_Y+TREEKNOBSIZE+h)
  290.  
  291.  
  292. #endif  /* LIBRARIES_GTDRAG_H */
  293.